/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package doan2database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author DongVan
 */
public class LoaiNguoiDung {
    private int m_IDLoaiNguoiDung;
	private String m_TenLoaiNguoiDung;
	
	public int getM_IDLoaiNguoiDung() {
		return m_IDLoaiNguoiDung;
	}
	public void setM_IDLoaiNguoiDung(int m_IDLoaiNguoiDung) {
		this.m_IDLoaiNguoiDung = m_IDLoaiNguoiDung;
	}
	public String getM_TenLoaiNguoiDung() {
		return m_TenLoaiNguoiDung;
	}
	public void setM_TenLoaiNguoiDung(String m_TenLoaiNguoiDung) {
		this.m_TenLoaiNguoiDung = m_TenLoaiNguoiDung;
	}
	public LoaiNguoiDung(int m_IDLoaiNguoiDung, String m_TenLoaiNguoiDung) {
		this.m_IDLoaiNguoiDung = m_IDLoaiNguoiDung;
		this.m_TenLoaiNguoiDung = m_TenLoaiNguoiDung;
	}
	public LoaiNguoiDung(){
		
	}
	
	
	AESEncrypt aes = new AESEncrypt();
	Datapro dataprovider = new Datapro();
	
	
	public ArrayList<LoaiNguoiDung> selected() {
		String sqlQuery = "select * from LOAI_NGUOI_DUNG";
		ArrayList<LoaiNguoiDung> listLoaiND = new ArrayList<LoaiNguoiDung>();
		ResultSet rs = dataprovider.Selected(sqlQuery);
		try {
			while (rs.next()) {
				LoaiNguoiDung loaiND = new LoaiNguoiDung();
				loaiND.m_IDLoaiNguoiDung = rs.getInt(1);
				String de = rs.getString(2);
				//System.out.println(de.length());
				loaiND.m_TenLoaiNguoiDung = aes.decryptString(de);
				listLoaiND.add(loaiND);
			}
			dataprovider.disconnect();
	        rs.close();
	        return listLoaiND;
	        
	    } catch ( SQLException ex) {
	        Logger.getLogger(Datapro.class.getName()).log(Level.SEVERE, null, ex);
	    }
		return null;
	}
	

	public boolean insert() {
		String tenLoaiND = aes.encryptString(this.m_TenLoaiNguoiDung);
		String query =  "insert into LOAI_NGUOI_DUNG values('"+ tenLoaiND + "')";
		boolean result =  dataprovider.Insert(query);
		dataprovider.disconnect();
		return result;
	}
	
	public boolean update(){
		String tenLoaiND = aes.encryptString(this.m_TenLoaiNguoiDung);
		String query = "update LOAI_NGUOI_DUNG set TenND = '"+ tenLoaiND +"' where IDLoaiND = " + this.m_IDLoaiNguoiDung + "\"";
		boolean result = dataprovider.Update(query);
		dataprovider.disconnect();
		return result;
	}
	
	public boolean delete(){
		String query = "delete from LOAI_NGUOI_DUNG where = " + this.m_IDLoaiNguoiDung + "\"";
		boolean result = dataprovider.Delete(query);
		dataprovider.disconnect();
		return result;
	}
}
